﻿using HY.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace HY.DataAchieve.EntityFramework
{

    /// <summary>
    /// 仓储基本接口
    /// </summary>
    /// <typeparam name="T">实体类型</typeparam>
    public interface IEFRepository<T> where T : class
    {
        /// <summary>
        /// 用于操作数据表
        /// </summary>
        IQueryable<T> Table { get; }

        /// <summary>
        /// 主键查询
        /// </summary>
        /// <param name="keyValues">键值</param>
        /// <returns>实体</returns>
        T Find(params object[] keyValues);

        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体</param>
        void Add(T entity);

        /// <summary>
        /// 批量添加实体
        /// </summary>
        /// <param name="entities">实体集合</param>
        void AddRange(IEnumerable<T> entities);

        /// <summary>
        /// 更改实体
        /// </summary>
        /// <param name="entity">实体对象</param>
        void Update(T entity);

        /// <summary>
        /// 批量更改实体
        /// </summary>
        /// <param name="entities">实体集合</param>
        void UpdateRange(IEnumerable<T> entities);

        /// <summary>
        /// 主键删除实体
        /// </summary>
        /// <param name="key">键值</param>
        void Delete(object key);

        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="entity">实体</param>
        void Delete(T entity);

        /// <summary>
        /// 批量删除实体
        /// </summary>
        /// <param name="entities">实体集合</param>
        void DeleteRange(IEnumerable<T> entities);
        
        /// <summary>
        /// 获取分页数据（单字段排序）
        /// </summary>
        /// <param name="condition">查询条件</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页大小</param>
        /// <param name="orderBy">排序条件</param>
        /// <param name="isAsc">是否升序</param>
        /// <returns>IQueryable 泛型集合</returns>
        Tuple<int, IList<T>> GetPageList<Tkey>(Expression<Func<T, bool>> condition, int pageIndex, int pageSize, Expression<Func<T, Tkey>> orderBy, bool isAsc);

        /// <summary>
        /// 获取分页数据（多字段排序）
        /// </summary>
        /// <param name="condition">查询条件</param>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="orderByExpression">排序条件</param>
        /// <returns>Tuple<符合条件的数据总数,分页数据></returns>
        Tuple<int, IList<T>> GetPageList(Expression<Func<T, bool>> condition, int pageIndex, int pageSize, params OrderByExpression[] orderByExpression);
    }
}
